package com.yeshen.pmtea.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.yeshen.pmtea.R;
import com.yeshen.pmtea.adapters.MyPagerAdapter;

import java.util.ArrayList;
import java.util.List;

public class TwoActivity extends AppCompatActivity {
    private ImageView mImageView;
    private ViewPager mViewPager;
    private Button mButton;
    private List<ImageView> data=new ArrayList<>();
    private int[] images=new int[]{R.mipmap.slide1,R.mipmap.slide2,R.mipmap.slide3};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_two);
        getSupportActionBar().hide();
        mImageView= (ImageView) findViewById(R.id.img);
        mViewPager= (ViewPager) findViewById(R.id.viewPager);
        mButton= (Button) findViewById(R.id.btn1);

        int lenth =images.length;
        for (int i = 0; i < lenth; i++) {
            ImageView imageView=new ImageView(this);
            imageView.setImageResource(images[i]);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            data.add(imageView);
        }
        mViewPager.setAdapter(new MyPagerAdapter(data,this));
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                 if (position==2){
                     mButton.setVisibility(View.VISIBLE);
                   //  Log.d("flag", "---------------onPageSelected: " );
                     mButton.setOnClickListener(new View.OnClickListener() {
                         @Override
                         public void onClick(View v) {
                             Intent intent=new Intent(TwoActivity.this,MainActivity.class);
                             startActivity(intent);
                             finish();
                         }
                     });
                 }else {
                     mButton.setVisibility(View.GONE);
                 }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }
}
